<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>会员余额充值</title>
<%@include file="../collect/meta.jsp"%>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/muser/musertop.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/muser/muserleft.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>余额充值</li>
						</ul>
					</div>
					<div class="page-content">
						<div class="row">
							<div class="col-xs-12">
								<form action="member!seekMember" name="seekMember" method="post">
									<fieldset>
										<legend align="center">充值搜索</legend>
										<div align="center">
											<input type="text" id="mobile" name="member.mobile"
												placeholder="手机号" maxlength="11" /> <input type="hidden"
												name="seekType" value="balance" /> <input type="button"
												class="btn btn-primary radius btn-sm" id="seek"
												value="搜&nbsp;索" />
											<%
												if (request.getParameter("error") != null) {
											%>
											&nbsp;&nbsp;&nbsp;<i style="color: red">该手机号还未注册会员</i>
											<%
												}
											%>
											<c:if test="${message==''}">
											</c:if>
											<c:if test="${message!=''}">
												<lable style="color: red">${message }</lable>
											</c:if>
										</div>
									</fieldset>
								</form>
								<br />
								<%
									if (request.getParameter("temp") != null) {
								%>
								<form action="member!balance" name="balance" method="post">
									<fieldset>
										<legend align="center">会员信息</legend>
										<div align="center">
											<table border="0" cellspacing="1" cellpadding="3">
												<tr>
													<td><div align="right">手&nbsp;机&nbsp;号:</div></td>
													<td><input type="hidden"
														name="member.mobile" value="${member.mobile }"
														id="memberMobile" />${member.mobile }</td>
												</tr>
												<tr>
													<td><div align="right">姓&nbsp;&nbsp;&nbsp;&nbsp;名:</div></td>
													<td><c:if test="${not empty member.name }">
			                                  			${member.name }
			                                  		</c:if></td>
												</tr>
												<tr>
													<td><div align="right">性&nbsp;&nbsp;&nbsp;&nbsp;别:</div></td>
													<td><c:if test="${not empty member.sex }">
			                                  			${member.sex }
			                                  		</c:if></td>
												</tr>
												<tr>
													<td><div align="right">注册时间:</div></td>
													<td>
														${fn:substring(member.createTime,
														0, fn:indexOf(member.createTime, "."))}</td>
												</tr>
												<tr>
													<td><div align="right">会员积分:</div></td>
													<td>
														${fn:substring(baseMember.score, 0, fn:indexOf(baseMember.score, ".0"))}
													</td>
												</tr>
												<tr>
													<td><div align="right">会员等级:</div></td>
													<td>${baseMember.level}</td>
												</tr>
												<tr>
													<td><div align="right">会员余额:</div></td>
													<td>
														<input type="hidden" id="balance" name="baseMember.balance"
															value="${baseMember.balance}" /> <fmt:formatNumber value="${baseMember.balance }" pattern="#0.00"/>

													</td>
												</tr>
												<tr>
													<td><div align="right">充值金额:</div></td>
													<td><input type="text" id="money"
														name="money" style="width: 100px;height: 30px"
														maxlength="6" /></td>
												</tr>
												<tr>
													<td colspan="2"><div align="center">
															<input type="button" class="btn btn-primary radius" id="but"
																value="充值" />
															<a class="btn btn-success radius" href="mbalance!goToAlipayBalance?member.id=${member.id }&member.eaId=${member.eaId }&shop.id=${shop.id }">支付宝充值</a>
														</div>
													</td>
												</tr>
												<tr>
													<td colspan="2"><div align="center">
															<b id="backMessage" style="font-size:25px;color:red;">充值成功!</b>
														</div> <input type="hidden" name="back" id="back"
														value="${back }" /></td>
												</tr>
												<input type="hidden" name="member.eaId" value="${member.eaId }" />
												<input type="hidden" name="member.id" value="${member.id }" />
												<input type="hidden" name="baseMember.id" value="${baseMember.id }" />
												<input type="hidden" name="shop.id" value="${shop.id }" />
											</table>
										</div>
										<legend align="center">充值记录</legend>
										<table class="table table-striped table-bordered table-hover">
											<tr>
												<th><div align="center">充值金额</div>
												</th>
												<th><div align="center">充值店铺</div>
												</th>
												<th><div align="center">操作人</div>
												</th>
												<th><div align="center">充值时间</div>
												</th>
											</tr>
											<c:forEach items="${balances}" var="balance"
												varStatus="status">
												<c:if test="${status.count<=10}">
													<tr>
														<td><div align="center">${balance.money }</div>
														</td>
														<td><div align="center">${balance.shopName }</div>
														</td>
														<td><div align="center">${balance.userName }</div>
														</td>
														<td><div align="center">${balance.createTime }</div>
														</td>
													</tr>
												</c:if>
											</c:forEach>
										</table>
									</fieldset>
								</form>
								<%
									}
								%>
							</div>
							<!-- /.col -->
						</div>
						<!-- /.row -->
					</div>
					<!-- /.page-content -->
				</div>
				<!-- /.main-content -->
			</div>
			<!-- /.main-container-inner -->
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<!-- /.main-container -->
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>

	<script type="text/javascript">
		$(document).ready(
				function() {

					var back = $("#back").val();
					if (back == "" || back == null) {
						$("#backMessage").hide();
					} else {
						setTimeout("$('#backMessage').hide()", 5000);
					}

					$("#seek").click(
							function() {
								var mobile = $("#mobile").val();
								if (mobile.length == 0) {
									alert("请填写手机号");
									return false;
								}
								if (!(/^1[3|5|8][0-9]\d{4,8}$/.test(mobile))
										|| mobile.length != 11) {
									alert("手机格式有误");
									return false;
								}
								seekMember.submit();
							});

					$("#but").click(function() {

						if (!confirm("确认充值？")) {
							return false;
						}

						var money = $("#money").val();
						//判断非负浮点小数
						var str = /^\d+(\.\d+)?$/;
						if (!str.test(money)) {
							alert("请输入充值金额");
							return false;
						}
						if (money < 100) {
							alert("最低充值一百");
							return false;
						}
						var memberMobile = $("#memberMobile").val();

						$.ajax({
							async : false,
							url : "member!timeOutBalance",
							type : "post",
							data : {
								"memberMobile" : memberMobile
							},
							datatype : "json",
							success : function(data) {
								var d = eval("(" + data + ")");
								var b = d.timeOut;
								if (b) {
									alert("30秒内不能重复充值同一个账号");
								} else {
									$("form[name='balance']").submit();
								}
							},
							error : function(request) {
								alert("Connection error");
							}
						});
					});
					
					$('.mbalance > a').css("color","red");
				});
	</script>
</body>
</html>